<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<html>
<body>
<script type="text/javascript">
	function edit(id,name,category,style,playerId,desc){
		$("#roomIdSpan").text(id);
		$("#roomId").val(id);
		$("#roomName").val(name);
		$("#category").val(category);
		$("#style").val(style);
		$("#playerId").val(playerId);
		$("#desc").text(desc);
	}
	
	function doSubmit(action){
		if(action != 0){
			$("#action").val(action);
			if(action == 1){
				$("#roomId").val(0);
			}
		}
//		if($("#roomName").val() == "" || $("#playerId").val() == "" || $("#desc").val() == ""){//可以设置房主为空
		if($("#roomName").val() == "" || $("#desc").val() == ""){
			alert("输入值不能为空");
			return;
		}
		$("#form1").submit();
	}
</script>

<jsp:include page="_room_header.jsp"></jsp:include>

<form action="list.do" method="post" id="form1">
<table  id="top">
	<tr>
		<td>房间id：</td>
		<td>
			<span id="roomIdSpan"></span>
			<input type="hidden" value="" name="roomId" id="roomId" />
		</td>
	</tr>
	<tr>	
		<td>房间名称： </td>
		<td>
			<input type="text" name="roomName" id="roomName" value=""/>
		</td>	
	</tr>
	<tr>	
		<td>
			房间分类:
		</td>
		<td>
			<select id="category" name="category">
				<option value=""></option>
		        <option value="1" selected="selected">1-华北</option>
		        <option value="2">2-华东</option>
		        <option value="3">3-华南</option>
		        <option value="4">4-活动</option>
			</select>
	  	</td>
	</tr>
	<tr>	
		<td>
			房间样式:
		</td>
		<td>
	  		<select name="style" id="style">
		        <option value=""></option>
		        <option value="1" selected="selected">1-流金岁月</option>
		        <option value="2">2-纯真年代</option>
		        <option value="3">3-花样年华</option>
		        <option value="4">4-活动场景</option>
		        <option value="5">5-魅力酒吧</option>
		        <option value="6">6-天空之城</option>
		        <option value="7">7-超时空要塞</option>
		      </select>
	  	</td>
	 </tr>
	<tr> 	
		<td>
			拥有者id:
		</td>
		<td>
	  		<input type="text" name="playerId" id="playerId" value=""/>
	  	</td>
	 </tr>
	<tr>   	
		<td>
			房间描述:
		</td>
		<td>
	  		<textarea rows="" cols="" id="desc" name="desc"></textarea>
	  	</td>
	</tr>
	<tr> 
		<td>
		</td>
		<td>
		 <input type="hidden" id="action" name="action" value="0"/>
		 	<input type="button" class="btn" onclick="doSubmit(1);" value="新增保存"></input>
		 	 <input type="button" class="btn" onclick="doSubmit(2);" value="保存修改"></input>
		 </td>
	</tr>
  </table>
  </form>
<table class="table table-bordered">
  <thead>
    <tr>
      <th>ID</th>
      <th>名称</th>
      <th>分类</th>
      <th>样式</th>
      <th>房主</th>
      <th>操作</th>
    </tr>
  </thead>
  <tbody>
  <c:forEach var="room" items="${list}">
    <tr>
      <td>${room.roomId}</td>
      <td>${room.name}</td>
      <td>${room.category}</td>
      <td>${room.style}</td>
      <td><tags:user id="${room.playerId}"/></td>
      <td><a href="#top" onclick="edit('${room.roomId}','${room.name}','${room.category}','${room.style}','${room.playerId}','${room.descr}');">编辑</a>
      <a href="?delete=${room.roomId}&roomName=${room.name}" onclick="return window.confirm('确认删除 ${room.roomId} ${room.name}');">删除</a></td>
    </tr>
  </c:forEach>
  </tbody>
</table>
</body>
</html>